<?php

/*
 * Niken Larasati
 * larasati.n@students.amikom.ac.id
 */

class propinsi extends CI_Controller {

    public function __construct() {
        parent::__construct();
    }

    function form_propinsi() {
        $this->template->load('halaman_v', 'admin/propinsi/tambah_propinsi_v');
    }

    function tambah() {
        if ($this->input->post('tambah') != NULL) {
            $data['idpropinsi'] = $this->input->post('idpropinsi');
            $data['kode_propinsi'] = $this->input->post('kode_propinsi');
            $data['propinsi'] = $this->input->post('propinsi');

            $this->load->model('umum_m');
            $this->umum_m->tambah('propinsi', $data);
            $this->tampil();
        }
    }

    function ubah($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $data['data_propinsi'] = $this->umum_m->ambil_data('propinsi', 'idpropinsi = ' . $id)->row();
            $this->template->load('halaman_v', 'admin/propinsi/ubah_propinsi_v', $data);
        } else {
            redirect('admin/propinsi');
        }
    }

    function simpan_ubah() { //kalau data tidak diubah,maka....?
        if ($this->input->post() != null) {
            $propinsi['idpropinsi'] = $this->input->post('idpropinsi');
            $propinsi['kode_propinsi'] = $this->input->post('kodepropinsi');
            $propinsi['propinsi'] = $this->input->post('propinsi');

            $this->load->model('umum_m');
            if ($this->umum_m->ubah('propinsi', $propinsi, 'idpropinsi', $propinsi['idpropinsi'])) {
                redirect('admin/propinsi/tampil');
            }
        }
    }

    function tampil() {
        $this->load->model('propinsi_m');
        $data['propinsi'] = $this->propinsi_m->ambil_data();
        $this->template->load('halaman_v', 'admin/propinsi/tampil_propinsi_v', $data);
    }

    function hapus($id = NULL) {
        if ($id != NULL) {
            $this->load->model('umum_m');
            $status = $this->umum_m->cek_relasi_tabel('kk', 'idpropinsi', $id);
            $status = $this->umum_m->cek_relasi_tabel('pindah_datang', 'idpindah_datang', $id);
            $status = $this->umum_m->cek_relasi_tabel('pindah_pergi', 'idpindah_pergi', $id);
            if ($status == 0) {
                $this->umum_m->hapus_data_tabel('propinsi', array('idpropinsi' => $id));
                $this->tampil();
            }
        }
    }

}

?>